package TestClass;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/arequest")
public class Session1Test extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1开启会话，创建一个会话对象session
        HttpSession session = req.getSession();
        //2.会话管理中设置数据，键值对
        session.setAttribute("ok","学习java");
        session.setAttribute("ok1","学习PHP");
        //3.获取设置的值 当前页面
        System.out.println("session.getAttribute(\"ok\") = " + session.getAttribute("ok"));
        System.out.println("session.getAttribute(\"ok1\") = " + session.getAttribute("ok1"));
    }
}
